package com.numberone.master.modules.sys.service;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.numberone.master.common.service.CrudService;
import com.numberone.master.common.utils.StringUtils;
import com.numberone.master.modules.sys.dao.SkillDao;
import com.numberone.master.modules.sys.dao.UserDao;
import com.numberone.master.modules.sys.entity.Skill;


@Service
@Transactional(readOnly = true)
public class SkillService extends CrudService<SkillDao, Skill> {
	
	@Autowired
	private UserDao userDao;
	
	@Transactional(readOnly = false)
	public void save(Skill skill) {
		if(StringUtils.isBlank(skill.getId())){
			dao.insert(skill);
		}else {
			dao.update(skill);
		}
	}
	
	@Transactional(readOnly = false)
	public void saveSkillComplain(Skill skill){
		if(StringUtils.isNoneBlank(skill.getId())){
			dao.deleteSkillComplain(skill.getId());
			dao.insertSkillComplain(skill);
		}else {
			dao.insertSkillComplain(skill);
		}
		
	}
	
	public List<Skill> findAllList(Skill skill) {
		// TODO Auto-generated method stub
		return dao.findAllList(skill);
	}
	
	@Transactional(readOnly = false)
	public void delete(Skill skill) {
		dao.deleteSkillComplain(skill.getId());
		dao.deleteSkillUser(skill.getId());
		dao.delete(skill);
	}

	public List<Skill> findListByUserId(String id) {
		return dao.findListByUserId(id);
	}

	public Skill getByName(String name) {
		return dao.getByName(name);
	}
	

}
